package com.dao.impl;

import com.bean.BhUser;
import com.dao.BhUserDao;
import com.util.AliPool;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * 用户Dao实现类
 */
public class BhUserDaoImpl implements BhUserDao {
    QueryRunner runner=new QueryRunner();
    @Override
    public BhUser sel( String sum,int num) throws SQLException {
        String sql = "select * from BhUser where uName=? and uID=?";
        Connection conn= AliPool.getConn();
        BhUser list=runner.query(conn,sql,new BeanHandler<BhUser>(BhUser.class),sum,num);
        conn.close();
        return list;
    }
    public BhUser chaa(int num) throws SQLException {
        String sql = "select * from BhUser where uID=?";
        Connection conn= AliPool.getConn();
        BhUser list=runner.query(conn,sql,new BeanHandler<BhUser>(BhUser.class),num);
        conn.close();
        return list;
    }

    @Override
    public List profile(int num) throws SQLException {
        String sql="select * from BhUser a inner join bhrole b on a.uSystem=b.id where uID=?";
        Connection conn= AliPool.getConn();
        List list=runner.query(conn,sql,new BeanListHandler<BhUser>(BhUser.class),num);
        conn.close();
        return list;
    }
    @Override
    public BhUser selname(String name) throws SQLException {
        String sql = "select * from BhUser where uName=?";
        Connection conn= AliPool.getConn();
        BhUser list=runner.query(conn,sql,new BeanHandler<BhUser>(BhUser.class),name);
        conn.close();
        return list;
    }
}
